<?php

namespace App\Console\Commands\HbGjPolicyCheck;

use App\Repositories\Contracts\PolicyUploadInterface;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Redis;

class HbGjCabinCheckSplit extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'hbgj:policySplit';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Command description';

    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle(PolicyUploadInterface $policyUploadInterface)
    {
        //

        $policies = $policyUploadInterface->count(['status'=>1]);
        if ($policies > 0 ) {

            $policyUploads = $policyUploadInterface->get(['status' => 1]);

            $items = ceil($policies / 5);
            for ($i = 1; $i <= 5; $i++) {

                foreach ($policyUploads as $key => $value) {

                    if ($key >= ($i - 1) * $items && $key < $i * $items) {

                        Redis::lpush('policyCheck' . $i, json_encode($value->toArray()));
                    }
                }
            }
        }

    }
}
